home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Tools / Turbo Pascal V7 / TVFM.ZIP / TRASH.PAS < prev    next >
Pascal/Delphi Source File  |  1992-11-03  |  3KB  |  129 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Vision File Manager Demo               }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. unit Trash;
  9.  
  10. {$X+,V-}
  11.  
  12. interface
  13.  
  14. uses Drivers, Objects, Views, App, Globals, Tools, Equ, MsgBox;
  15.  
  16. type
  17.  
  18.   { Trash can object }
  19.   PTrashCan = ^TTrashCan;
  20.   TTrashCan = object(TView)
  21.     constructor Init(var Bounds: TRect);
  22.     procedure Draw; virtual;
  23.     procedure HandleEvent(var Event: TEvent); virtual;
  24.     function GetPalette: PPalette; virtual;
  25.     procedure SetState(AState: Word; Enable: Boolean); virtual;
  26.     procedure Reposition(var R: TRect);
  27.   end;
  28.  
  29.  
  30. implementation
  31.  
  32. const
  33.   CTrashCan : string[Length(CGrayWindow)] = CGrayWindow;
  34.  
  35. { TTrashCan }
  36.  
  37. constructor TTrashCan.Init(var Bounds: TRect);
  38. begin
  39.   inherited Init(Bounds);
  40.   Options := Options or (ofSelectable + ofTopSelect);
  41.   EventMask := EventMask or evBroadcast;
  42. end;
  43.  
  44. function TTrashCan.GetPalette: PPalette;
  45. begin
  46.    GetPalette := @CTrashCan;
  47. end;
  48.  
  49. procedure TTrashCan.Draw;
  50. var
  51.   B: TDrawBuffer;
  52.   C: Word;
  53. begin
  54.   if State and sfDragging <> 0 then C := 3
  55.   else if State and sfSelected = 0 then C := 1
  56.   else C := 2;
  57.   C := GetColor(C);
  58.   MoveStr(B, #209#209#216#209#209, C);
  59.   WriteLine(0, 0, Size.X, 1, B);
  60.   MoveStr(B, 'Trash', C);
  61.   WriteLine(0, 1, Size.X, 1, B);
  62.   MoveStr(B, #192#193#193#193#217, C);
  63.   WriteLine(0, 2, Size.X, 1, B);
  64. end;
  65.  
  66. procedure TTrashCan.HandleEvent(var Event:TEvent);
  67. var
  68.   Mover: PFileMover;
  69.   Where: TPoint;
  70.   SaveConfirm: Boolean;
  71.   Extent: TRect;
  72.   Msg: String;
  73.  
  74.   procedure DeleteFile(F: PFileRec); far;
  75.   begin
  76.     SafeDelete(Mover^.Dir + '\' + F^.Name + F^.Ext);
  77.   end;
  78.  
  79. begin
  80.   inherited HandleEvent(Event);
  81.  
  82.   if (Event.What = evBroadcast) and (Event.Command = cmItemDropped) then
  83.   begin
  84.     Mover := Event.InfoPtr;
  85.     Desktop^.MakeGlobal(Mover^.Origin, Where);
  86.     if MouseInView(Where) then
  87.     begin
  88.       ClearEvent(Event);
  89.       if Mover^.Items^.Count = 1 then Msg := RezStrings^.Get(sDelSingle)
  90.       else Msg := RezStrings^.Get(sDelMult);
  91.       if MessageBox(Msg, nil, mfConfirmation +
  92.         mfYesButton + mfNoButton) = cmYes then
  93.       begin
  94.         SaveConfirm := ConfirmDelete;
  95.         ConfirmDelete := False;
  96.         Mover^.Items^.ForEach(@DeleteFile);
  97.         ConfirmDelete := SaveConfirm;
  98.         InvalidateDir(Mover^.Dir);
  99.       end;
  100.     end;
  101.   end;
  102.  
  103.   if Event.What = evMouseDown then
  104.   begin
  105.     Owner^.GetExtent(Extent);
  106.     DragView(Event, dmDragMove, Extent, Size, Size);
  107.   end;
  108.  
  109. end;
  110.  
  111. procedure TTrashCan.SetState(AState: Word; Enable: Boolean);
  112. begin
  113.   inherited SetState(AState, Enable);
  114.   if AState and sfSelected <> 0 then
  115.     SetCmdState([cmNext, cmPrev], Enable);
  116.   if (AState and (sfSelected + sfFocused) <> 0) or
  117.     (AState and (sfActive + sfDragging) <> 0) then
  118.     DrawView;
  119. end;
  120.  
  121. procedure TTrashCan.Reposition(var R: TRect);
  122. begin
  123.   Inc(R.A.X);
  124.   R.A.Y := R.B.Y - 4;
  125.   MoveTo(R.A.X, R.A.Y);
  126. end;
  127.  
  128. end.
  129.